package com.rui.cn.provider.controller.system;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.rui.cn.entity.system.SysUser;
import com.rui.cn.provider.service.system.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @PostMapping(value = "/selectUserList")
    public List<SysUser> selectUserList(@RequestBody Pagination page,@RequestParam("sate") Integer state){
        return sysUserService.selectUserList(page,state);
    }

    @GetMapping(value = "/selectByUsername/{username}")
    public SysUser selectByUsername(@PathVariable("username") String username){
        return sysUserService.selectByUsername(username);
    }

    @PostMapping(value = "/userList")
    public Page<SysUser> userList(@RequestBody Page pagination,@RequestParam(required = false,value = "search") String search,@RequestParam(required = false,value = "sortBy") String sortBy,@RequestParam(required = false,value = "order") String order){
        return sysUserService.userList(pagination,search,sortBy,order);
    }

    @GetMapping(value = "/getUserInfo/{id}")
    public SysUser getUserInfo(@PathVariable("id") Integer id){
        return  sysUserService.getUserInfo(id);
    }

    @PostMapping(value = "/insertMyUser")
    public int insertMyUser(@RequestBody SysUser user){
        sysUserService.insertMyUser(user);
        return user.getId();
    }

    @GetMapping(value = "/selectById/{id}")
    public SysUser selectById(@PathVariable("id") Integer id){
        return sysUserService.selectById(id);
    }

    @PutMapping(value = "/updateById")
    public boolean updateById(@RequestBody SysUser user){
       return sysUserService.updateById(user);
    }

    @DeleteMapping(value = "/deleteBatchIds")
    public boolean deleteBatchIds(@RequestBody List<Integer> integers){
        return sysUserService.deleteBatchIds(integers);
    }
}
